using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BarrierCreateCenter : MonoBehaviour
{
    //随机数相关变量
    public int Num1, Num2;
    public int[] Num11 = new int[3]; //0:Sign 1:Window 2:Barrier
    public int[] Num21 = new int[2]; //0:lfet 1:right
    public int[] Num22 = new int[3]; //0:lfet 1:right 2:mid
    private int Sum, flag;

    [Header("每隔多少时间生成一次")]
    public float CreateTime = 15.0f;
    private float m_timer = 0;
    

    // Start is called before the first frame update
    void Start()
    {
        for (int i = 0; i < 3; ++i) {
            Num11[i] = 0;
        }
        for (int i = 0; i < 2; ++i) {
            Num21[i] = 0;
        }
        for (int i = 0; i < 3; ++i) {
            Num22[i] = 0;
        }
    }

    // Update is called once per frame
    void Update()
    {
        //每隔多少秒生成一次
        m_timer += Time.deltaTime;
        if (m_timer >= CreateTime) {
            Create();
            m_timer = 0;
        }
    }

    private void Create() {
        //生成Num1
        flag = 0;
        for (int i = 0; i < 3; ++i) {
            if (Num11[i] == 1) {
                ++flag;
            }
        }
        if (flag == 3) {
            for (int i = 0; i < 3; ++i) {
                Num11[i] = 0;
            }
        }
        while (true) {
            Num1 = Random.Range(0, 3);
            if (Num11[Num1] == 0) {
                break;
            }
        }


        //生成Num2
        if (Num1 == 2) {
            flag = 0;
            for (int i = 0; i < 3; ++i) {
                if (Num22[i] == 1) {
                    ++flag;
                }
            }
            if (flag == 3) {
                for (int i = 0; i < 3; ++i) {
                    Num22[i] = 0;
                }
            }
            while (true) {
                Num2 = Random.Range(0, 3);
                if (Num22[Num2] == 0) {
                    break;
                }
            }
        }
        else {
            if (Num21[0] == 1 && Num21[1] == 1) {
                Num21[0] = 0;
                Num21[1] = 0;
            }
            while (true) {
                Num2 = Random.Range(0, 2);
                if (Num21[Num2] == 0) {
                    break;
                }
            }
        }
        

        Sum = Num1 * Num2;
        switch (Sum) { //TOOD
            case 5:
                //Sign left
                break;
            case 10:
                //Win left
                break;
            case 15:
                //Barrier left
                break;
            case 4:
                //Sign right
                break;
            case 8:
                //Win right
                break;
            case 12:
                //Barrier right
                break;
            case 9:
                //Barrier mid
                break;
        }
    }
}
